package com.wrs.wrsfcmpush.utils;

import android.app.Service;
import android.content.Context;
import android.util.Log;

import com.blankj.utilcode.util.AppUtils;

public class TaskUtils {
    public static  int i = 0;
  public  static   void startTask(String tag, Context context, Service service) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {

                    try {
                        Thread.sleep(2000);

                        Log.d(tag, "====保活服务===数据支持====");
                        String pkg = "com.wrs.project.jpush";
                        boolean isRuning = AppUtils.isAppRunning(pkg);
                        if (isRuning) {
                            boolean isForeground = AppUtils.isAppForeground(pkg);
                            if (isForeground) {
                                Log.d(tag,"====app 在前台运行");
                            } else {
                                i ++;
                                Log.d(tag,"====app 没有在前台运行 i:" + i);
                                if (i >= 4) {
//                                    launchApp(tag);
//                                    startNot(context, service);
//                                    if (InComeCallMgr.handle != null) {
//                                        InComeCallMgr.handle.inComing();
//                                    }
                                }
                            }
                        } else {
                            Log.d(tag,"====app 没有在运行中");
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
        }).start();
    }

    public static void startNot(Context context, Service service) {
      NotificationUtils.startFullNot(context, service);
    }

    public static void launchApp(String tag) {
        Log.d(tag,"====launchApp");
        String pkg = "com.wrs.project.jpush";
        AppUtils.launchApp(pkg);
    }


}
